package com.bss.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import com.andy.basics.Dao;
import com.bss.dao.CountryDao;
import com.bss.dao.PlaceDao;
import com.bss.dao.StateDao;
import com.bss.model.Country;
import com.bss.model.Place;
import com.bss.model.State;

@Service
@Scope("session")
public class PlaceService extends com.andy.basics.Service<Place> {

	@Autowired
	protected CountryDao countryDao;

	@Autowired
	private StateDao stateDao;

	@Autowired
	private PlaceDao placeDao;

	private Place place = new Place();

	private State state = new State();

	private Country country = new Country();

	private Place selectedPlace;

	private State selectedState;

	private Country selectedCountry;

	public Place getSelectedPlace() {
		return this.selectedPlace;
	}

	public void setSelectedPlace(Place selectedPlace) {
		this.selectedPlace = selectedPlace;
	}

	public State getSelectedState() {
		return this.selectedState;
	}

	public void setSelectedState(State selectedState) {
		this.selectedState = selectedState;
	}

	public Country getSelectedCountry() {
		return this.selectedCountry;
	}

	public void setSelectedCountry(Country selectedCountry) {
		this.selectedCountry = selectedCountry;
	}

	public Place getPlace() {
		return this.place;
	}

	public void setPlace(Place place) {
		this.place = place;
	}

	public State getState() {
		return this.state;
	}

	public void setState(State state) {
		this.state = state;
	}

	public Country getCountry() {
		return this.country;
	}

	public void setCountry(Country country) {
		this.country = country;
	}

	@Override
	public Dao<Place> getDao() {
		return this.placeDao;
	}

	public void addPlace() {
		this.place.setState(this.stateDao.findById(this.getSelectedState().getId()));
		this.placeDao.persist(this.place);
		this.place = new Place();
	}

	public void addState() {
		this.state.setCountry(this.countryDao.findById(this.getSelectedCountry().getId()));
		this.stateDao.persist(this.state);
		this.state = new State();
	}

	public void addCountry() {
		this.countryDao.persist(this.country);
		this.country = new Country();
	}

}
